const { resolve } = require("path");
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";

const processEnv = process.env.VUE_APP_ENV; // 区分环境(值：production、development、test)

let publicPath = '/' // 静态资源引用路径
if (processEnv === 'prod') {
  publicPath = '/v3Test/' // 正式环境静态资源css、js等cdn路径
} else if (processEnv === 'test') {
  publicPath = '/v3Test/' // 测试环境静态资源css、js等cdn路径
} else {
  publicPath = '/v3Test/'
}

export default defineConfig({
  base: publicPath,
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  //启动服务配置
  server: {
    host: "0.0.0.0",
    port: 8000,
    open: true,
    https: false,
    proxy: {},
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "/common/assets/css/global.scss";`,
      },
    },
  },
  define: {
    "process.env": process.env,
  },
  build: {
    rollupOptions: {
      input: {
        index: resolve(__dirname, "index.html"),
        xtMain: resolve(__dirname, "xtMain/xtMain.html"),
        xtChannel: resolve(__dirname, "xtChannel/xtChannel.html"),
      },
    },
  },
});
